package test;

import java.util.*;

import core.Transaction;
import core.TransactionDirection;
import data.IDataProvider;
import data.IFilter;

public class DummyProvider implements IDataProvider
{
	private List<String> transactionTypes;
	private List<Transaction> transactions;
	private String profileName = "Profil";
	private Calendar cal = Calendar.getInstance(Locale.getDefault());

	public DummyProvider(){
		transactionTypes = new ArrayList<String>();
		transactionTypes.add("Plat");
		transactionTypes.add("Jídlo");
		transactionTypes.add("Bydlení");

		transactions = new ArrayList<Transaction>();
		cal.set(2009, 12, 15);
		transactions.add(new Transaction(5000, "Plat Česká pojišťovna",
					transactionTypes.get(0), TransactionDirection.INCOME, cal.getTime()));
		cal.set(2009, 12, 22);
		transactions.add(new Transaction(1000, "Doučování Aleš", 
					transactionTypes.get(0), TransactionDirection.INCOME, cal.getTime()));
		cal.set(2009, 12, 1);
		transactions.add(new Transaction(120, "Čína", 
					transactionTypes.get(1), TransactionDirection.EXPENSE, cal.getTime()));
		cal.set(2009, 12, 3);
		transactions.add(new Transaction(1000, "Nákup jídlo", 
					transactionTypes.get(1), TransactionDirection.EXPENSE, cal.getTime()));
		cal.set(2009, 12, 9);
		transactions.add(new Transaction(3000, "Nájem", 
					transactionTypes.get(2), TransactionDirection.EXPENSE, cal.getTime()));
		cal.set(2009, 12, 13);
		transactions.add(new Transaction(950.50, "Uklízečka", 
					transactionTypes.get(2), TransactionDirection.EXPENSE, cal.getTime()));
	}

	@Override public String getProfileName(){
		return profileName;
	}

	@Override public void renameProfile(String newName){
		profileName = newName;
	}

	@Override public void addTransaction(Transaction t){
		transactions.add(t);
	}

	@Override public void transactionEdited(Transaction t){
	}

	@Override public void deleteTransaction(Transaction t){
		transactions.remove(t);
	}

	@Override public Collection<Transaction> getTransactions(
				IFilter<Transaction> filter){
		HashSet<IFilter<Transaction>> filterSet =
					new HashSet<IFilter<Transaction>>();
		filterSet.add(filter);
		return getTransactions(filterSet);
	}

	@Override public Collection<Transaction> getTransactions(
				Collection<IFilter<Transaction>> filters){
		List<Transaction> confoming = new ArrayList<Transaction>();
		main: for(Transaction transaction : transactions){
			for(IFilter<Transaction> filter : filters){
				if(!filter.conforms(transaction)){
					continue main;
				}
			}
			confoming.add(transaction);
		}
		return confoming;
	}

	@Override public Collection<String> getUsedTypes(
				TransactionDirection direction){
		return getUsedTypes(direction, null);
	}

	@Override public Collection<String> getUsedTypes(
				TransactionDirection direction, Date from){
		Collection<String> types = new HashSet<String>();
		for(Transaction transaction : transactions){
			if(transaction.getDirection() == direction && 
						(from == null || transaction.getDate().after(from))){
				types.add(transaction.getType());
			}
		}
		for(String string : types){
			System.out.println(string);
		}
		return types;
	}
}
